<template>
  <div>
    <div class="radio">
      <el-radio-group v-model="PatentType" size="mini" @input="radioUpdate">
        <el-radio-button v-for="item in radioList" :key="item.id" :label="item.name">{{
          item.name
        }}</el-radio-button>
      </el-radio-group>
    </div>

    <el-table :data="tableData" style="width: 100%">
      <el-table-column
        v-if="PatentType == '中国专利金奖'"
        prop="sno_name"
        label="名称"
        width="180"
      >
      </el-table-column>
      <el-table-column v-else prop="company" label="公司名称" width="180">
      </el-table-column>
      <el-table-column
        v-if="PatentType == '中国专利金奖'"
        prop="sno"
        label="专利号"
        width="180"
      >
      </el-table-column>
      <el-table-column prop="year" label="年份" width="180"> </el-table-column>
      <el-table-column prop="des" label="荣誉">
        <template slot-scope="scope">
          {{ PatentType }}
        </template>
      </el-table-column>
    </el-table>

    <div class="pagination">
      <el-pagination
        background
        small
        @current-change="handleCurrentChange"
        :current-page="page"
        :page-size="5"
        layout="total, prev, pager, next, jumper"
        :total="parseInt(count)"
        align="left"
        :pager-count="5"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { honorList,honorType } from "@/api/configApi";
export default {
  data() {
    return {
      id: this.$route.query.id,
      tableData: [],
      PatentType: "",
      page: 1,
      count: 0,
      radioList: [],
      limit: 10,
      region_id: this.$store.state.user.region_id,
    };
  },
  props: {
    PatentNumber: {
      type: Object,
      default: () => ({}),
    },
    form_admin: {
      handler(newV, oldV) {
        honorType({
          region_id: this.region_id,
          type: 1,
        }).then((res) => {
          this.radioList = res;
          this.PatentType = this.radioList[0].name;
          this.getHonorlist();
        });
      },
      deep: true,
    },
  },
  components: {},
  mounted() {
    honorType({
      region_id: this.region_id,
      type: 1,
    }).then((res) => {
      this.radioList = res;
      this.PatentType = this.radioList[0].name;
      this.getHonorlist();
    });
  },
  methods: {
    getHonorlist() {
      let typeId 
      this.radioList.map(res => {
        if(res.name == this.PatentType){
          typeId = res.id
        }
      })
      honorList({
        type_id: typeId,
        page: this.page,
        limit: this.limit,
        keywords: this.form_admin.company,
      }).then((res) => {
        this.tableData = res.list;
        this.count = res.count;
      });
    },
    radioUpdate(index) {
      this.PatentType = index;
      this.page = 1;
      this.count = 0;
      this.getHonorlist();
    },
    handleCurrentChange(currentPage) {
      this.page = currentPage;
      this.getHonorlist();
    },
  },
};
</script>

<style scoped lang="less">
.pagination {
  margin: 10px auto;
}
@media (max-width: 1360px) {
}

@media (max-width: 1280px) {
}

@media (max-width: 768px) {
}
</style>
